package com.example.springmvcdemo4;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@RequestMapping("/resp")
@Controller
public class ResponseController {
    @RequestMapping("/re1")
    public String getRe1(){
        return "/test.html";
    }
    @ResponseBody
    @RequestMapping("/re0")
    public String getRe0(){
        return "<h1>又连跪了<h1>";
    }
    @ResponseBody
    @RequestMapping("/re2")
    public String getRe2(){
        return "获取数据";
    }
    //返回json
    @ResponseBody
    @RequestMapping("re3")
    public HashMap<String,String> getRe3(){
        HashMap<String,String> map = new HashMap<>();
        map.put("k1","v1");
        map.put("k2","v2");
        map.put("k3","v3");
        map.put("k4","v4");
        return map;
    }
    @ResponseBody
    @RequestMapping("re4")
    public String setStatus(HttpServletResponse response){
        response.setStatus(418);
        return "设置状态码成功";
    }
    //设置返回类型
    @RequestMapping(value = "return",produces = "applicatin/json")
    @ResponseBody
    public String returnJson(){
        return "{\"success\":true}";
    }
}
